package com.googlecode.cryptoid;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;


public class EncryptedMessage extends MessageTab {
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        start();
    }
	
	protected void onResume(){
		super.onResume();
		if(ViewMessage.needsCryption){
			Matrix.encrypt();
			ViewMessage.needsCryption = false;
			if(!toMessageList())
				Toast.makeText(this, R.string.couldntwritemessage, Toast.LENGTH_LONG).show();
		}
		if(ViewMessage.encrypted != "")
			messageText.setText((CharSequence) ViewMessage.encrypted);
	}
	
	protected void onPause(){
		super.onPause();
		String messageString = messageText.getText().toString();
		if(!messageString.equals(ViewMessage.encrypted) && messageString.length() != 0){
			ViewMessage.encrypted = messageString;
			ViewMessage.needsCryption = true;
		}
	}
	
	public void crypt(View button){
		Matrix.decrypt();
		Toast.makeText(this, R.string.decrypted, Toast.LENGTH_LONG).show();
		if(!toMessageList())
			Toast.makeText(this, R.string.couldntwritemessage, Toast.LENGTH_LONG).show();
	}
	
}
